<%-- 
    Document   : Login
    Created on : 16-ene-2014, 22:50:11
    Author     : kyox
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:include page="../../_LoginLayout.html"/>

<div class="col-sm-3 col-md-3"></div>
<div class="col-sm-6 col-md-6 jumbotron">
    
    <form class="form-horizontal" role="form" action="controller/Usuario/validacionLogin.jsp" method="post">
        <div class="form-group usuarioDiv">
            <label for="usuario" class="col-sm-4 control-label">Usuario</label>
            <div class="col-sm-8">
                <input type="text" class="form-control" id="usuario" name="usuario" placeholder="Usuario">
            </div>
        </div>
        <div class="form-group passwordDiv">
            <label for="inputPassword" class="col-sm-4 control-label">Contrase&ntilde;a</label>
            <div class="col-sm-8">
                <input type="password" class="form-control" id="inputPassword" name="password" placeholder="Contraseña">
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-3 col-sm-6">
                <button type="submit" id="enviar" class="btn btn-primary">Ingresar</button>
                <img class="cargando" src="/SICOM_CCI/view/img/ajax-loader.gif"/>
            </div>
        </div>
    </form>
    <div class="alert alert-danger">
        <button type="button" class="closeAlert btn-link" aria-hidden="true">&times;</button>
        <div id="mensaje"></div>
    </div>
</div>
<div class="col-sm-3 col-md-3 "></div>

<jsp:include page="../../_FooterLayout.html"/>

<script type="text/javascript">
    $('#enviar').click(function(event){
        event.preventDefault();
        var error = '';
        if($('#usuario').val()==''){
            $('.usuarioDiv').addClass('has-error');
            error ='<p>Usuario faltante.</p>'
        }
        if($('#inputPassword').val()==''){
            $('.passwordDiv').addClass('has-error');
            error =  error + ' <p>Contrase&ntilde;a faltante.</p>'
        }
        if(error.length>0){
            $('#mensaje').html(error);
            $('.alert').show('slow');
        } else {
            
            ajaxPost("controller/UsuarioController.jsp",
                                "login="+$('#usuario').val()+","+$('#inputPassword').val(), "json", 'login');
        }
    });
    $('#usuario').keyup(function(){
        if($('.usuarioDiv').hasClass('has-error')){
            $('.usuarioDiv').removeClass('has-error');
            $('.alert').hide('slow');
        }
    });
    $('#inputPassword').keyup(function(){
        if($('.passwordDiv').hasClass('has-error')){
            $('.passwordDiv').removeClass('has-error');
            $('.alert').hide('slow');
        }
    });
</script>